<?php

declare(strict_types=1);
/**
 * 创建人 : Forpastime
 * 创建时间: 2023/4/10 14:45
 * 个人主页 : http://forpastime.com
 */
namespace App\Service;

use App\Event\SmsSend;
use Hyperf\Di\Annotation\Inject;
use Psr\EventDispatcher\EventDispatcherInterface;

class SmsService
{
    /**
     * @Inject
     * @var EventDispatcherInterface
     */
    private $eventDispacher;

    /**
     * @param $mobile
     * @param $type
     */
    public function send($mobile, $type)
    {
        $code = mt_rand(100000, 999999);

        // 实例化事件
        $smsSend = new SmsSend($mobile, $code, $type);

        // 调度
        $this->eventDispacher->dispatch($smsSend);

        if ($smsSend->hasSend) {
            return true;
        }
        return false;
    }

    public function check()
    {
        // check放在每个业务场景去调SmsCheck事件
    }
}
